package com.abc.cloud.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.abc.cloud.vo.file.FileTagVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.abc.cloud.entity.FileTagEntity;
import com.abc.cloud.service.FileTagService;
import com.abc.cloud.common.utils.PageUtil;
import com.abc.cloud.common.utils.Result;



/**
 * 文件标签表
 *
 * @author LiJunXi
 * @email 2770063826@qq.com
 * @date 2023-10-27 13:09:54
 */
@Api(tags = "文件标签接口")
@RestController
@RequestMapping("/fileTag")
public class FileTagController {
    @Autowired
    private FileTagService fileTagService;

    /**
     * 列表
     */
    @ApiOperation(value = "文件标签列表")
    @GetMapping("/list")
    public Result list(@RequestParam Map<String, Object> params){
        PageUtil page = fileTagService.queryPage(params);

        return Result.success(page, "page");
    }


    /**
     * 根据文件ID获取关键字信息
     */
    @ApiOperation(value = "根据文件ID获取关键字信息")
    @GetMapping("/info/{fileId}")
    public Result<List<FileTagEntity>> info(@PathVariable("fileId") Long fileId){
        List<FileTagEntity> fileTagList = fileTagService.getInfoByFileId(fileId);

        return Result.success(fileTagList, "获取关键字成功");
    }

    /**
     * 保存
     */
    @ApiOperation(value = "保存标签")
    @PostMapping("/save")
    public Result save(@RequestBody FileTagVo fileTagVo){
		fileTagService.saveFileTag(fileTagVo);

        return Result.success(null, "操作成功");
    }

    /**
     * 修改
     */
    @ApiOperation(value = "修改")
    @PutMapping("/update")
    public Result update(@RequestBody FileTagEntity fileTag){
		fileTagService.updateById(fileTag);

        return Result.success(null, "操作成功");
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除")
    @PutMapping("/delete")
    public Result delete(@RequestBody Long[] ids){
		fileTagService.removeByIds(Arrays.asList(ids));

        return Result.success(null, "操作成功");
    }

}
